package NetWork;

import org.junit.Test;

import java.io.*;
import java.net.*;
import java.util.Arrays;

public class SocketTest {
    @Test
    public static void InetAddressTest() throws UnknownHostException {
        InetAddress[] allByName = InetAddress.getAllByName("m.djtv1.cc");
        System.out.println(Arrays.toString(allByName));

    }
@Test
    public static void TestURL(){
        try {
            URL url = new URL("https://down.qq.com/qqweb/PCQQ/PCQQ_EXE/PCQQ2021.exe");
            URLConnection urlConnection = url.openConnection();
            InputStream inputStream = urlConnection.getInputStream();
            OutputStream outputStream = new FileOutputStream("\\D:QQ.exe");
            byte[] bytes = new byte[1024];
            int len;
            while ((len=inputStream.read(bytes))!=-1){
                outputStream.write(bytes,0,len);
            }


        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    public static void main(String[] args) throws UnknownHostException {
       TestURL();
    }

}
